<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<!DOCTYPE html>
<html lang="ko">
<head>
	<%@ include file="/include/header.jsp" %>
	<link rel="stylesheet" href="<%=cp %>/mobile/skin/board/notice/style.css">
	<%@ include file="/include/commonRes.jsp" %>
	<link rel="stylesheet" href="<%=cp %>/css/board.css">
	
	
	<script type="text/javascript">
		function validate(){
			var mb_auth_code=$("#mb_auth_code");
			var mb_name=$("#mb_name");
			var mb_id=$("#mb_id");
			var mb_hp=$("#mb_hp");		
			var mb_team_code=$("#mb_team_code");
			
			var mb_hp1=$("#mb_hp1");
			var mb_hp2=$("#mb_hp2");
			var mb_hp3=$("#mb_hp3");
			var mb_password=$("#mb_password");
			var mb_dept_code=$("#mb_dept_code");
			
			var mb_name_val=mb_name.val();
			var mb_id_val=mb_id.val();
			var mb_hp_val=mb_hp.val();	
			
			var mb_dept_code_val=mb_dept_code.val();
			var mb_auth_code_val=mb_auth_code.val();
			var mb_team_code_val=mb_team_code.val();
			
			var mb_hp1_val=mb_hp1.val();
			var mb_hp2_val=mb_hp2.val();
			var mb_hp3_val=mb_hp3.val();
			
			var mb_password_val=mb_password.val();
			
			
			if(mb_name_val==null || mb_name_val==""){
				alert("이름을 입력해주세요.");
				mb_name.focus();
				return false;
			}
			if(getBytes(mb_name_val)>255) {
				alert("이름의 글자수가 허용범위를 초과했습니다.");
				mb_name.focus();
				return false;
			}
			
			if(mb_dept_code_val==null || mb_dept_code_val==""){
				alert("부서명을 선택해주세요.");
				mb_dept_code.focus();
				return false;
			}
			
			if(mb_team_code_val==null || mb_team_code_val==""){
				alert("팀명을 선택해주세요.");
				mb_team_code.focus();
				return false;
			}
			
			if(mb_auth_code_val==null || mb_auth_code_val==""){
				alert("직책을 선택해주세요.");
				mb_auth_code.focus();
				return false;
			}
			
			if(mb_id_val==null || mb_id_val==""){
				alert("아이디를 입력해주세요.");
				mb_id.focus();
				return false;
			}
			
			if(getBytes(mb_id_val)>20) {
				alert("아이디의 글자수가 허용범위를 초과했습니다.");
				mb_id.focus();
				return false;
			}
			
			<c:if test="${mode=='insert' }">
			if(mb_password_val==null || mb_password_val==""){
				alert("비밀번호를 입력해주세요.");
				mb_password.focus();
				return false;
			}
			
			if(getBytes(mb_password_val)>255) {
				alert("비밀번호의 글자수가 허용범위를 초과했습니다.");
				mb_password.focus();
				return false;
			}
			</c:if>
			
			if(mb_hp1_val!=null && mb_hp1_val!="" && mb_hp2_val!=null && mb_hp2_val!="" && mb_hp3_val!=null && mb_hp3_val!=""){
				if(!checkPhoneNum()){
					return false;
				}
				mb_hp_val=mb_hp1_val+"-"+mb_hp2_val+"-"+mb_hp3_val;
				mb_hp.val(mb_hp_val);
			} else {
				if((mb_hp1_val==null || mb_hp1_val=="") && (mb_hp2_val==null || mb_hp2_val=="") && (mb_hp3_val==null || mb_hp3_val=="")){
					//모두 빈칸일땐 통과
				}else{
					if(!checkPhoneNum()){
						return false;
					}
				}
			}
			return true;
		}
	
		function save(){
			if(!validate()){
				return false;
			}			
			if(!confirm("저장 하시겠습니까?")){
				return false;
			}
			return true;
		}
		
		
		$(function(){
			
			$("#submitLink").click(function(){
				$("#editFrm").submit();
			});
		});
		
		function checkPhoneNum(){
			var mb_hp1=$("#mb_hp1");
			var mb_hp2=$("#mb_hp2");
			var mb_hp3=$("#mb_hp3");

			var mb_hp1_val=mb_hp1.val();
			var mb_hp2_val=mb_hp2.val();
			var mb_hp3_val=mb_hp3.val();
			
			
			if(mb_hp1_val==null || mb_hp1_val==""){
				alert("핸드폰번호 1번째를 입력해주세요.");
				return false;
			}
			
			if(isNaN(mb_hp1_val)) {
				alert("핸드폰번호 1번째는 숫자만 허용됩니다.");
				return false;
			}
			
			
			if(mb_hp2_val==null || mb_hp2_val==""){
				alert("핸드폰번호 2번째를 입력해주세요.");
				return false;
			}
			
			if(isNaN(mb_hp2_val)) {
				alert("핸드폰번호 2번째는 숫자만 허용됩니다.");
				return false;
			}
			
			if(mb_hp3_val==null || mb_hp3_val==""){
				alert("핸드폰번호 3번째를 입력해주세요.");
				return false;
			}
			
			if(isNaN(mb_hp3_val)) {
				alert("핸드폰번호 3번째는 숫자만 허용됩니다.");
				return false;
			}
			return true;
		}
	</script>
</head>
<body>

	<c:set var="mb_auth_code" value="${member.mb_auth_code }" />
	<c:set var="mb_team_code" value="${member.mb_team_code }" />
	<c:set var="mb_name" value="${member.mb_name }" />
	<c:set var="mb_id" value="${member.mb_id }" />
	<c:set var="mb_password" value="${member.mb_password }" />
	<c:set var="mb_auth_level" value="${member.mb_auth_level}" />
	<c:set var="mb_hp" value="${member.mb_hp }" />
	<c:set var="mb_dept_code" value="${member.mb_dept_code }" />
	<c:set var="mb_team_code" value="${member.mb_team_code }" />
	<c:set var="mb_hp_str" value="${fn:split(mb_hp,'-')}" />
	<c:set var="mb_hp1" value="${mb_hp_str[0]}" />
	<c:set var="mb_hp2" value="${mb_hp_str[1]}" />
	<c:set var="mb_hp3" value="${mb_hp_str[2]}" />

	
	<%@include file="/include/mainMenuHeader.jsp" %>
	<div id="wrapper">
    	<div id="container">
			<script src="<%=cp%>/js/viewimageresize.js"></script>
			
			<!--<div id="bo_v_table">&nbsp;</div>  -->
			<form action="<%=cp%>/org/org_edit.do" method="post" id="editFrm" name="editFrm" onsubmit="return save();">
				
				<article id="bo_v" style="width:100%">
				    <header>
				        <c:if test="${param.mb_id==sessionScope.ss_mb.mb_id }">
				        	<h2>정보수정</h2>
				        </c:if>
				        
				        <c:if test="${param.mb_id!=sessionScope.ss_mb.mb_id }">
				        	<c:if test="${mode=='insert' }">
					        	<h2>직원정보등록</h2>
							</c:if>
							<c:if test="${mode=='update' }">
								<h2>직원정보수정</h2>
							</c:if>
				        </c:if>
				    </header>
				
				    <section>&nbsp;</section>
				    
				    <div class="tbl_head01 tbl_wrap">
				        <div class="org_li_table_view">
							<section>&nbsp;</section>
							
							<input type="hidden"  id="mode" name="mode" value="${mode }"/> 
							<ul>
								<li class="title first">이 름</li>
								<li class="content first">
									<c:if test="${sessionScope.ss_mb.mb_auth_code==7 ||  sessionScope.ss_mb.mb_auth_code==8}">
										<input type="text" id="mb_name" name="mb_name" value="${mb_name }"/>
									</c:if>
									<c:if test="${sessionScope.ss_mb.mb_auth_code!=7 &&  sessionScope.ss_mb.mb_auth_code!=8}">
										<input type="hidden" id="mb_name" name="mb_name" value="${mb_name }"/>
										${mb_name }
									</c:if>
								</li>
							</ul>
							<ul>
								<li class="title">부서명</li>
								<li class="content">
									<c:if test="${sessionScope.ss_mb.mb_auth_code==7 ||  sessionScope.ss_mb.mb_auth_code==8}">
										<select name="mb_dept_code" id="mb_dept_code">
											<option value="">선택</option>
											<option value="0" <c:if test="${mb_dept_code==0 }">selected</c:if>>없음</option>
											<option value="1" <c:if test="${mb_dept_code==1 }">selected</c:if>>서비스1과</option>
											<option value="2" <c:if test="${mb_dept_code==2 }">selected</c:if>>서비스2과</option>
											<option value="3" <c:if test="${mb_dept_code==3 }">selected</c:if>>원장</option>
											<option value="4" <c:if test="${mb_dept_code==4 }">selected</c:if>>관리자</option>
										</select>
									</c:if>
									<c:if test="${sessionScope.ss_mb.mb_auth_code!=7 &&  sessionScope.ss_mb.mb_auth_code!=8}">
										<select  disabled="disabled">
											<option value="">선택</option>
											<option value="0" <c:if test="${mb_dept_code==0 }">selected</c:if>>없음</option>
											<option value="1" <c:if test="${mb_dept_code==1 }">selected</c:if>>서비스1과</option>
											<option value="2" <c:if test="${mb_dept_code==2 }">selected</c:if>>서비스2과</option>
											<option value="3" <c:if test="${mb_dept_code==3 }">selected</c:if>>원장</option>
											<option value="4" <c:if test="${mb_dept_code==4 }">selected</c:if>>관리자</option>
										</select>
										<input type="hidden" id="mb_dept_code" name="mb_dept_code" value="${mb_dept_code}">
									</c:if>
								</li>
							</ul>
							<ul>
								<li class="title">팀</li>
								<li class="content">
									<c:if test="${sessionScope.ss_mb.mb_auth_code==7 ||  sessionScope.ss_mb.mb_auth_code==8}">
										<select name="mb_team_code" id="mb_team_code">
											<option value="">선택</option>
											<option value="0" <c:if test="${mb_team_code==0 }">selected</c:if>>없음</option>
											<option value="1" <c:if test="${mb_dept_code==1 && mb_team_code==1 }">selected</c:if>>데스크</option>
											<option value="2" <c:if test="${mb_dept_code==1 && mb_team_code==2 }">selected</c:if>>검안</option>
											<option value="3" <c:if test="${mb_dept_code==2 && mb_team_code==1 }">selected</c:if>>진료</option>
											<option value="4" <c:if test="${mb_dept_code==3 && mb_team_code==3 }">selected</c:if>>원장</option>
										</select>
									</c:if>
									<c:if test="${sessionScope.ss_mb.mb_auth_code!=7 &&  sessionScope.ss_mb.mb_auth_code!=8}">
										<select disabled="disabled" >
											<option value="">선택</option>
											<option value="0" <c:if test="${mb_team_code==0 }">selected</c:if>>없음</option>
											<option value="1" <c:if test="${mb_dept_code==1 && mb_team_code==1 }">selected</c:if>>데스크</option>
											<option value="2" <c:if test="${mb_dept_code==1 && mb_team_code==2 }">selected</c:if>>검안</option>
											<option value="3" <c:if test="${mb_dept_code==2 && mb_team_code==1 }">selected</c:if>>진료</option>
											<option value="4" <c:if test="${mb_dept_code==3 && mb_team_code==3 }">selected</c:if>>원장</option>
										</select>
										<input type="hidden"  name="mb_team_code" id="mb_team_code" value="${mb_team_code}">
									</c:if>
								</li>
							</ul>
							
							<ul>
								<li class="title">직 책</li>
								<li class="content">
									
									
									
									<c:if test="${sessionScope.ss_mb.mb_auth_code==7 ||  sessionScope.ss_mb.mb_auth_code==8}">
										<select name="mb_auth_code" id="mb_auth_code">
											<option value="">선택</option>
											<option value="1" <c:if test="${mb_auth_code==1 }">selected</c:if>>사원</option>
											<option value="2" <c:if test="${mb_auth_code==2 }">selected</c:if>>팀장</option>
											<option value="3" <c:if test="${mb_auth_code==3 }">selected</c:if>>과장</option>
											<option value="4" <c:if test="${mb_auth_code==4 }">selected</c:if>>차장</option>
											<option value="5" <c:if test="${mb_auth_code==5 }">selected</c:if>>부장</option>
											<option value="6" <c:if test="${mb_auth_code==6 }">selected</c:if>>원장</option>
											<option value="7" <c:if test="${mb_auth_code==7 }">selected</c:if>>대표원장</option>
											<option value="8" <c:if test="${mb_auth_code==8 }">selected</c:if>>관리자</option>
											<c:if test="${mb_auth_level==6 }">
												<option value="9" <c:if test="${mb_auth_code==9 }">selected</c:if>>최고관리자</option>
											</c:if>
										</select>
									
									</c:if>
									
									<c:if test="${sessionScope.ss_mb.mb_auth_code!=7 &&  sessionScope.ss_mb.mb_auth_code!=8}">
										<select disabled="disabled">
											<option value="">선택</option>
											<option value="1" <c:if test="${mb_auth_code==1 }">selected</c:if>>사원</option>
											<option value="2" <c:if test="${mb_auth_code==2 }">selected</c:if>>팀장</option>
											<option value="3" <c:if test="${mb_auth_code==3 }">selected</c:if>>과장</option>
											<option value="4" <c:if test="${mb_auth_code==4 }">selected</c:if>>차장</option>
											<option value="5" <c:if test="${mb_auth_code==5 }">selected</c:if>>부장</option>
											<option value="6" <c:if test="${mb_auth_code==6 }">selected</c:if>>원장</option>
											<option value="7" <c:if test="${mb_auth_code==7 }">selected</c:if>>배원장</option>
											<option value="8" <c:if test="${mb_auth_code==8 }">selected</c:if>>관리자</option>
											<c:if test="${mb_auth_level==6 }">
												<option value="9" <c:if test="${mb_auth_code==9 }">selected</c:if>>최고관리자</option>
											</c:if>
										</select>
										<input type="hidden" name="mb_auth_code" id="mb_auth_code" value="${mb_auth_code }">
									</c:if> 
									
								</li>
							</ul>
							<ul>
								<li class="title">아이디<br/></li>
								<li class="content">
									<c:if test="${mode=='insert' }">
										<input type="text" id="mb_id" name="mb_id" value="${mb_id }"/>
									</c:if>
									<c:if test="${mode=='update' }">
										<input type="hidden" id="mb_id" name="mb_id" value="${mb_id }"/>
										${mb_id }
									</c:if>	
								</li>
							</ul>
							<ul>
								<li class="title">비밀번호</li>
								<li class="content">
									<input type="password" id="mb_password" name="mb_password" value=""/>
								</li>
							</ul>
							<ul>
								<li class="title end">연락처</li>
								<li class="content end">
									<input type="text" id="mb_hp1" name="mb_hp1" class="size40" value="${mb_hp1 }" maxlength="3"/>-<input type="text" id="mb_hp2" name="mb_hp2" class="size40" value="${mb_hp2}" maxlength="4"/>-<input type="text" id="mb_hp3" name="mb_hp3" class="size40" value="${mb_hp3 }" maxlength="4" />
									<input type="hidden" id="mb_hp"  name="mb_hp" value="${mb_hp }" />
								</li>
							</ul>
						</div>
					</div>
					<section>&nbsp;</section>
				    <div id="bo_v_bot">
				        <!-- 링크 버튼 -->
	                    <!-- <ul class="bo_v_nb">
	                        <li>
	                        	<a href="./board.php?bo_table=notice&amp;wr_id=11" class="btn_b01">다음글</a>
	                        </li>        
	                    </ul> -->
				        
				        <ul class="bo_v_com">
				            <li>
				            	<c:if test="${mode=='insert' }">
									<a href="#" class="btn_b01" id="submitLink">등록</a>
								</c:if>
								<c:if test="${mode=='update' }">
									<a href="#" class="btn_b01" id="submitLink">수정</a>
								</c:if>
			            	</li>            
			            	<li><a href="#" class="btn_b01" onclick="history.back();">취소</a></li>
				        </ul>
			    	</div>
				</article>
			</form>
		</div>
	</div>
	<%@ include file="/include/footer.jsp" %>
</body>
</html>